package com.penjin.android.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.penjin.android.R;
import com.penjin.android.activity.kaoqin.KaoqinTongjiActivity;

import java.util.ArrayList;

/**
 * Created by fengjw on 2016/3/14.
 */
public class GridAdapter extends BaseAdapter {
    private ArrayList<String> mNameList = new ArrayList<String>();
    private LayoutInflater mInflater;
    private Context mContext;
    private ArrayList<Drawable> mDrawableList = new ArrayList<Drawable>();

   // LinearLayout.LayoutParams params;

    //, ArrayList<Drawable> drawableList
    public GridAdapter(Context context, ArrayList<String> nameList){
        mNameList=nameList;
       // mDrawableList=drawableList;
        mContext=context;
        mInflater=LayoutInflater.from(context);

    }

    public int getCount(){
        return mNameList.size();
    }

    public Object getItem(int position) {
        return mNameList.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ItemViewTag viewTag;

        if (convertView == null){
            convertView = mInflater.inflate(R.layout.gridview_item, null);

            viewTag = new ItemViewTag((TextView) convertView.findViewById(R.id.imageview));

            convertView.setTag(viewTag);

        }else{

            viewTag= (ItemViewTag) convertView.getTag();
        }

        viewTag.mImageview.setText(mNameList.get(position));
        viewTag.mImageview.setTextColor(android.graphics.Color.parseColor("#FFFFFF"));
       // viewTag.mName.setBackgroundColor(android.graphics.Color.parseColor("#E84C3D"));

        String[] color={"#E84C3D","#3598DB","#E67F22","#58D68D","#9A59B5","#33CC99","#34495E","#F1C40F"};
       // viewTag.mImageview.setBackground();

        viewTag.mImageview.setBackgroundColor(android.graphics.Color.parseColor(color[position]));
        viewTag.mImageview.setBackgroundResource(R.drawable.shape+position);
//        viewTag.mImageview.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent=new Intent(KaoqinTongjiActivity.this,);
//            }
//        });
        return convertView;

    }


    class ItemViewTag{
       // protected TextView mName;
        protected TextView mImageview;

        public ItemViewTag(TextView imageView){
         //   this.mName=name;
            this.mImageview=imageView;
        }
    }

}
